//
//  MeatShopCartHeader.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/22.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatShopCartHeader.h"

@implementation MeatShopCartHeader

#pragma mark - lifecycle methods

- (void)setupUI
{
    self.backgroundColor = KWhiteColor;
    
    
    [self addSubview:self.shopCartLab];
    [self addSubview:self.shopCancelBtn];
    
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 52, KScreenWidth , 1)];
    self.line.path = path.CGPath;
    self.line.hidden = NO;
    
    CAShapeLayer *maskLay = [CAShapeLayer layer];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, KScreenWidth, 56) byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];
    maskLay.path = maskPath.CGPath;
    self.layer.mask = maskLay;
    
}


- (void)setupLayout
{
    self.height = 56;
    
    {
        _shopCartLab.mj_x = 15;
        _shopCartLab.mj_y = 15;
        _shopCartLab.width = 100;
        _shopCartLab.height = 22;
    }
    
    {
        _shopCancelBtn.mj_y = 15;
        _shopCancelBtn.width = 100;
        _shopCancelBtn.height = 22;
        _shopCancelBtn.mj_x = KScreenWidth - _shopCancelBtn.width - 15;
    }
}



#pragma mark - setter methods

#pragma mark - getter methods

- (UIView *)contentView{
    
    if (!_contentView) {
        _contentView = [[UIView alloc] init];
        _contentView.backgroundColor = KWhiteColor;
        
        UIRectCorner corners = UIRectCornerTopLeft|UIRectCornerTopRight;
        UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:_contentView.frame byRoundingCorners:corners cornerRadii:CGSizeMake(8, 8)];
        CAShapeLayer *shape = [[CAShapeLayer alloc] init];
        [shape setPath:rounded.CGPath];
        _contentView.layer.mask = shape;
        
    }
    return _contentView;
}


- (UILabel *)shopCartLab{
    
    if (!_shopCartLab) {
        _shopCartLab = [UILabel makeLabelWithText:@"购物车" textColor:UIColorFromRGB(0x262626) font:mFont(16) textAliment:0];
    }
    return _shopCartLab;
}


- (UIButton *)shopCancelBtn{
    
    if (!_shopCancelBtn) {
        _shopCancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _shopCancelBtn.titleLabel.textAlignment = NSTextAlignmentRight;
        NSMutableAttributedString *aims = [@"   一键清空 " createAttributingByIcon:@"meat_shopcart_cancel" downIndexImage:nil textColor:UIColorFromRGB(0x262626) font:mFont(14)];
        [_shopCancelBtn setAttributedTitle:aims forState:UIControlStateNormal];
        _shopCancelBtn.isNeedAnimation = YES;
        
        kWeakSelf(self);
        _shopCancelBtn.tapBlock = ^{
            if (weakself.dealShopCartCancelBlock) {
                weakself.dealShopCartCancelBlock();
            }
        };
    }
    return _shopCancelBtn;
}



@end
